add polygon_chord#2969
Conversation
|
Maybe we should consider adding shapely as a dependency? It might simplify some of these computations without having to re-implement all of computational geometry. |
I already looked into using shapely for a way to support trigger / voltage patches in the past here: |
|
This is possible, but the function itself is very small, so using an external library would be unnecessary. I wouldn’t make it more complex than it is. |
| X-coordinates of the starting points of the polygon edges. | ||
| ri_y : ndarray of shape (N,) | ||
| Y-coordinates of the starting points of the polygon edges. | ||
| vi_x : ndarray of shape (N,) |
There was a problem hiding this comment.
I think we should deduce these (if needed) from the vertices. You can write a helper for this.
There was a problem hiding this comment.
Yes, I'd also prefer the vertices as input. But maybe the function as it is here is fine and that transformation is made once outside of this function.
|
|
||
| Parameters | ||
| ---------- | ||
| mu_x : float |
There was a problem hiding this comment.
These should be quantities, as we discussed offline, the best would be to use telescope coordinate system lat/lon.
There was a problem hiding this comment.
Also, perhaps tuples of (x,y) or arrays of them would be more straightforward to define points (arrays of points)
|
|
||
| Returns | ||
| ------- | ||
| float |
There was a problem hiding this comment.
Should be also a unit of length (or angular, equivalent in the telescope frame)
| - Each polygon edge is defined as: | ||
| (x, y) = (ri_x, ri_y) + t * (vi_x, vi_y), with 0 <= t < 1 | ||
| - The function computes intersections by solving a 2D linear system. | ||
| - A small epsilon_d (`1e-20`) is added to the denominator to avoid division by zero. |
There was a problem hiding this comment.
why not using
try:
...
except ZeroDivisionError:
# determinant is zero, the cord goes on the edge, handle this
There was a problem hiding this comment.
Just remember that catching an exception is quite a bit slower than adding an epsilon, so if you need this to be fast, the epsilon method might be better. Also if you want to use numba to speed things up
| SQRT2 = np.sqrt(2) | ||
|
|
||
|
|
||
| def polygon_chord(mu_x, mu_y, phi, ri_x, ri_y, vi_x, vi_y): |
There was a problem hiding this comment.
This function should be njit, as it will be called. If possible, it would also be good if it could be vectorized over multiple tiles.
Polygonal description of the chord.
096_arbitrary_shaped_mirror_and_polygon_chord.pdf
Uploading 096_arbitrary_shaped_mirror_and_polygon_chord.odp…